package de.hska.reka.websockets.model;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;

import javax.naming.InvalidNameException;

public class ControllerMethodMap {
	private HashMap<String, ClassMethod> controllerMethodHashmap = new HashMap<String, ClassMethod>();
	
	public void put(String controllerName, ClassMethod classMethod) {
		System.out.println("adding " + controllerName + "." + classMethod.getMethod().getName());
		this.controllerMethodHashmap.put(controllerName + "." + classMethod.getMethod().getName(), classMethod);
	}
	
	public void execute(String methodControllerName, Object[] params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, InvalidNameException {
		ClassMethod classMethod = this.controllerMethodHashmap.get(methodControllerName);
		if(classMethod==null) {
			throw new InvalidNameException("Method not found");
		}
		classMethod.invoke(params);
	}
	
	public void setHandler(Object handler) {
		
	}
}
